package com.rgzn.charpter5.controtller;

import com.rgzn.charpter5.entity.UserPOJO;
import com.rgzn.charpter5.service.UserService;
import com.rgzn.charpter5.util.JwtUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.*;

@Slf4j
@CrossOrigin(origins = "http://localhost:5173")
@RestController
public class UserController {
    @Autowired
    UserService userService;
    @PostMapping("/login")
    public String login(@RequestBody UserPOJO userpo) {
        log.info(":"+userpo);
        //验证账号密码
        User user = userService.login(userpo.getUsername(), userpo.getPassword());
        //返回token
        String token = JwtUtil.createJwt(user);
        System.out.println(JwtUtil.resolveJwt(token));
        return token;
    }
}
